// pages/my/myset/myset.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:'',
    Allsex:["男","女"],
    sexs:'',
    sexIndex:0,
    name:'',
    password:'',
    phone:'',
    id:'',
    isSetInfo:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
    this.setData({
      isSetInfo: getApp().globalData.isSetInfo,
      name: getApp().globalData.account.realName,
      id: getApp().globalData.account.idCard,
      phone: getApp().globalData.account.mobile,
      password: getApp().globalData.account.password,
      sex: getApp().globalData.account.sex
    })
    let that = this
    //填充头像
    if (getApp().globalData.userInfo){
      that.setData({
        userInfo: getApp().globalData.userInfo
      })
    }else{
      wx.getStorage({
        key: 'userInfo',
        success: function(res) {
          that.setData({
            userInfo: res.data
          })
        },
      })
    }
  },

  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //接收用户输入的姓名
  inputName: function (e) {
    this.setData({
      name: e.detail.value,
    })
    console.log("姓名:"+this.data.name)
  },
  inputId: function (e) {
  
    this.setData({
      id: e.detail.value,
    })
    console.log("身份证:"+this.data.id)
  },
  bind_sex: function (e) {

    console.log(e)
    this.setData({
      sexIndex:e.detail.value
    })
    if(this.data.sexIndex==0){
      this.setData({
        sexs:'男'
      })
    }else{
      this.setData({
        sexs:'女'
      })
    }
    console.log('性别发生选择改变，携带值为'+this.data.sexs);
  },
  //手机phone号
  inputPhone: function (e) {
    this.setData({
      phone: e.detail.value,
    })
    console.log("手机:"+this.data.phone)
  },
  //密码
  inputPassword: function (e) {
    this.setData({
      password: e.detail.value,
    })
    console.log("密码:"+this.data.password)
  },
 
  //提交按钮，向数据库中存入数据
  tijiao: function () {
    var phone = "",
    phone =  this.data.phone;
    console.log(phone.length)
    if(this.data.phone==null||this.data.password==null||this.data.name==null||phone.length!=11)
    {
      wx.showModal({
        title: '提示!',
        content: '请输入正确信息',
      })
    }else{
    var that = this;
    console.log("全局"+getApp().globalData.openId)
    wx.request({
      // url:"http://59.110.42.131:8080/trans_inspector",
     // url: 'https://172.17.76.17:8080/trans_inspector',
      //url:'https://www.jfbkn.top:444/trans_inspector',
      url:'http://101.37.14.167:8001/set_userInfo',
      method:'POST',
      // header: {
      //   'content-type': 'application/x-www-form-urlencoded'
      // },
      data:{
        id:getApp().globalData.account.id,
        address:null,
        idCard:that.data.id,
        isMember:1,
        mobile:that.data.phone,
        password:that.data.password,
        realName:that.data.name,
        score:0,
        sex:that.data.sexs,
        openid:getApp().globalData.openId,
        username:getApp().globalData.userInfo.nickName,
        we_chat_openid:getApp().globalData.openId   
      },
      success: function(res){
        console.log(res)
        getApp().globalData.isSetInfo =true
        console.log(getApp().globalData.checked)
        that.setData({
          name: getApp().globalData.account.realName,
          id: getApp().globalData.account.idCard,
          phone: getApp().globalData.account.mobile,
          password: getApp().globalData.account.password,
          sex: getApp().globalData.account.sex
        })
      },
      fail: function(res){
        console.log(res)
      }
    })
    wx.navigateBack({   //成功后跳转回原页面
      url: '../my'
    })
  }
     
  }
})